<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 * @version		$Id:$
 */

$this->headTitle($this->TRANSLATOR->translator('page_layout_page_title') . ' - ' . $this->TRANSLATOR->translator('common_admin_title'));
?>
<div class="content">
	<div class="box header mb0">
		<div class="head"><div></div></div>
		<h2 class="g_a_breadcump">
			<a class="fl" href="<?php echo $this->url('core_dashboard_index'); ?>"><?php echo $this->TRANSLATOR->translator('dashboard_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="<?php echo $this->url('core_page_list', array('template_id' => $this->template)); ?>"><?php echo $this->TRANSLATOR->translator('page_breadcump'); ?></a>
			<small class="icon arrow_right" style="display: block;"></small>
			<a class="fl" href="javascript: void(0);"><?php echo $this->TRANSLATOR->translator('page_layout_breadcump'); ?></a>
			<div class="clear"></div>
		</h2>
	</div>
</div>
<div class="content">
	<div class="desc">
		<div class="body g_a_body">
			<form action="<?php echo $this->url('core_page_layout', $this->pageData); ?>" method="post" id="gCorePageLayout">
				<div class="fl">
					<h4 class="g_a_h4"><?php echo $this->TRANSLATOR->translator('page_layout_guide'); ?></h4>
					<ul>
						<li><?php echo $this->TRANSLATOR->translator('page_name'); ?>: <b><?php echo $this->pageData['name']; ?></b></li>
						<li><?php echo $this->TRANSLATOR->translator('page_route'); ?>: <b><?php echo $this->pageData['route']; ?></b></li>
						<li><?php echo $this->TRANSLATOR->translator('page_template'); ?>: <b><?php echo $this->template; ?></b></li>
					</ul>
				</div>
				<div class="fr">
					<?php if ($this->ACL->isAllowed('layout', 'page')) : ?>
					<a class="fl g_a_tip gCorePageLayoutSave g_a_submit_button mr5" href="javascript: void(0);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_button_layout_save_title')); ?>"></a>
					<?php endif; ?>
					<a class="fl g_a_tip g_a_cancel_button mr5" href="javascript: history.go(-1);" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_back_button', 'core')); ?>"></a>
					<?php if ($this->ACL->isAllowed('list', 'page')) : ?>
					<a class="fl g_a_tip" href="<?php echo $this->url('core_page_list', array('template_id' => $this->template)); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_actions_list_title')); ?>">
						<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_list_icon.png" style="padding: 0 5px 0 0;" />
					</a>
					<?php endif; ?>
					<?php if ($this->ACL->isAllowed('add', 'page')) : ?>
					<a class="fl g_a_tip" href="<?php echo $this->url('core_page_add', array('template_id' => $this->template)); ?>" title="<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_actions_add_title')); ?>">
						<img src="<?php echo $this->APP_RESOURCE_SERVER; ?>/templates/<?php echo $this->APP_TEMPLATE; ?>/skins/<?php echo $this->APP_SKIN; ?>/images/actions_add_icon.png" style="padding: 0 5px 0 0;" />
					</a>
					<?php endif; ?>
				</div>
				<div class="g_a_line"></div>
				<!--  -->
				<?php if (isset($this->blocks) && $this->blocks) : ?>
				<?php foreach ($this->blocks as $index => $block) : ?>
				<!--  -->
				<?php if ($index > 0 && $index % 3 == 0) : ?>
				<div class="clear"></div>
				<?php endif; ?>
				<div class="col w33">
					<div class="content">
						<div class="box header mb0">
							<div class="head"><div></div></div>
							<h2 class="g_a_breadcump">
								<a class="fl g_a_blockname" style="text-decoration: none;" href="javascript: void(0);"><?php echo $block; ?></a>
								<div class="clear"></div>
							</h2>
						</div>
					</div>
					<div class="content">
						<div class="desc">
							<div class="body g_a_widget_dropped" id="g_a_block_<?php echo $block; ?>">
								<?php if (isset($this->blocksData[$block])) : ?>
								<script type="text/javascript">
									$('#g_a_block_<?php echo $block; ?>').addClass('g_a_ajax_loading');
									var params = 'route=<?php echo $this->pageData['route']; ?>|<?php echo $this->blocksData[$block]['paramString']; ?>';
									<?php if ($this->blocksData[$block]['type'] == 'action') : ?>
									var module = 'core';
									var name = 'maincontent';
									<?php else : ?>
									var module = '<?php echo $this->blocksData[$block]['module']; ?>';
									var name = '<?php echo $this->blocksData[$block]['name']; ?>';
									<?php endif; ?>
									
									Gio.Core.Widget.Loader.queueAction(module, name, 'config', params, $('#g_a_block_<?php echo $block; ?>'), function(response) {
										configString = (response == '') ? '' : '<li><?php echo $this->TRANSLATOR->translator('common_config_title'); ?><br />' + response + '</li>';
										var string = '<ul>'
											+ configString
											+ '<li><?php echo $this->TRANSLATOR->translator('common_config_load_by_ajax'); ?> <input type="checkbox" name="blocks[<?php echo $this->blocksData[$block]['index']; ?>][load]" value="ajax"<?php if ($this->blocksData[$block]['load'] == 'ajax') : ?> checked="checked"<?php endif; ?> /></li>'
											+ '<li><?php echo $this->TRANSLATOR->translator('common_config_cache_use'); ?> <input type="checkbox" name="blocks[<?php echo $this->blocksData[$block]['index']; ?>][cache][enable]" value="true"<?php if ($this->blocksData[$block]['cache']['enable']) : ?> checked="checked"<?php endif; ?> /></li>'
											+ '<li><?php echo $this->TRANSLATOR->translator('common_config_cache_timeout'); ?><br /> <input class="text" type="text" name="blocks[<?php echo $this->blocksData[$block]['index']; ?>][cache][timeout]" value="<?php echo $this->blocksData[$block]['cache']['timeout']; ?>" style="width: 60px; margin-top: 5px;" /></li>'
											+ '<li><?php echo $this->TRANSLATOR->translator('common_config_invisible'); ?> <input type="checkbox" name="blocks[<?php echo $this->blocksData[$block]['index']; ?>][visible]" value="false"<?php if (!$this->blocksData[$block]['visible']) : ?> checked="checked"<?php endif; ?> /></li>'
											+ '</ul>'
											+ '<div class="clear">'
											+ '<p class="last buttons_demo">'
//											+ '<a href="javascript: void(0);" onclick="javascript: Gio.Core.Widget.Loader.queueAction(\'<?php echo $this->blocksData[$block]['module']; ?>\', \'<?php echo $this->blocksData[$block]['name']; ?>\', \'show\', params, $(\'#g_a_block_<?php echo $block; ?>\'), \'\');" class="button green"><small class="icon check"></small><span><?php echo $this->TRANSLATOR->translator('common_button_preview'); ?></span></a>'
											+ '<a href="javascript: void(0);" onclick="javascript: $(this).parents(\'.g_a_widget_dropped\').html(\'<p><?php echo $this->TRANSLATOR->translator('common_no_data'); ?><p>\');" class="button red"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('common_button_delete'); ?></span></a>'
											+ '</p>'
											+ '</div><div class="clear"></div>'
											+ '<input type="hidden" name="blocks[<?php echo $this->blocksData[$block]['index']; ?>][block_name]" value="<?php echo $block; ?>">';
										$($('#g_a_block_<?php echo $block; ?>')).html(string);
										$($('#g_a_block_<?php echo $block; ?>')).removeClass('g_a_ajax_loading');
									});
								</script>
								<?php else : ?>
								<p><?php echo $this->TRANSLATOR->translator('common_no_data'); ?></p>
								<div class="clear"></div>
								<?php endif; ?>
							</div>
						</div>
						<div class="body_footer">
							<div class="bottom_left"><div class="bottom_right"></div></div>
						</div>
					</div>
				</div>
				<!--  -->
				<?php endforeach; ?>
				<?php endif; ?>
				<div class="clear"></div>
				<?php if (isset($this->tokenElement)) : ?><?php echo $this->tokenElement; ?><?php endif; ?>
			</form>
		</div>
	</div>
	<div class="body_footer">
		<div class="bottom_left"><div class="bottom_right"></div></div>
	</div>
</div>
<script type="text/javascript">
Gio.Core.Widget.index = '<?php echo count($this->blocks); ?>';
$(document).ready(function() {
	<?php if (($string = $this->MESSENGER->printMessages()) != null) : ?>
	Gio.Message.success('<?php echo $string; ?>');
	<?php endif; ?>

	$('.gCorePageLayoutSave').click(function() {
		/**
		 * Show g_a_ajax_loading element
		 */
		$('#g_a_ajax_loading').show();
		$.ajaxq('core_page_layout', {
			type: 'POST',
			url: '<?php echo $this->url('core_page_layout', $this->pageData); ?>',
			data: $('#gCorePageLayout').serialize(),
			success: function(response) {
				if (response == 'RESULT_OK') {
					Gio.Message.success('<?php echo $this->STRING->escape($this->TRANSLATOR->translator('page_actions_layout_success')); ?>');
				} else {
					Gio.Message.error('<?php echo $this->STRING->escape($this->TRANSLATOR->translator('common_error_message')); ?>');
				}
				/**
				 * Hide g_a_ajax_loading element
				 */
				$('#g_a_ajax_loading').hide();
			}
		});
	});
});
</script>